<?php
namespace application\views;
use application\utilities\Utility;

class File extends \application\auth\Normal {

	public function load() {
		global $concerto;
		$file = getQueryVar('file');
		
		
		// Get relative directory stuff out of the file, because otherwise they could see anything
		
		$file = str_replace('../', '', $file);
		$file = str_replace('./', '', $file);
		
		
		// Get extension
		$pos = Utility::strposall($file, '.');
		
		$extension = substr($file, ($pos[(count($pos) - 1)] + 1));
		switch($extension) {
			case 'js':
				header('Content-Type: text/javascript');
				break;
			case 'css':
				header('Content-Type: text/css; charset=UTF-8');
				break;
			case 'jpg':
			case 'jpeg':
				header('Content-Type: image/jpeg');
				break;
			case 'png':
				header('Content-Type: image/png');
				break;
				
		}
		
		if(file_exists(CN_APPLICATION_PATH . 'includes/'.$file)) {
			$contents = file_get_contents( CN_APPLICATION_PATH. 'includes/'.$file);
			$contents = str_replace('CN_URL', CN_URL, $contents);
			echo $contents;
		}
		else {
			$concerto->Loader->loadError(ERROR_CONTENT_NOT_FOUND);
		}
	}
	
	
}
?>